import os

def poolClean(path,poolNum):
    files = os.listdir(path)
    file_nums = len(files)
    files.sort(key=lambda fn: os.path.getmtime(path + '\\' + fn))
    if file_nums > poolNum:
        for i in range(file_nums - poolNum):
            os.remove(path + files[i])
if __name__ == '__main__':
    poolClean()






